﻿using SdlDotNet.Graphics;
//using SdlDotNet.;
using System.Drawing;
using NielsRask.Mucus;
using NielsRask.K242.Rendering;

namespace RenderTest1
{
	public class GuiLayer : LayerBase
	{
		Size size;
		Surface surface;
		Form form;
		BuildingSelector selector;

		public BuildingSelector Selector
		{
			get { return selector; }
		}
		public GuiLayer( Size size )
		{
			this.surface = new Surface( size );
			surface.Fill( Color.Black );
			surface.TransparentColor = Color.Black;
			surface.Transparent = true;
			this.form = new Form( surface );
			form.Controls.Add( new Label( new Point( 10, 10 ), "Test tingeling" ) );

			selector = new BuildingSelector( new Size( 70, 180 ) );
			selector.Position = new Point( 400, 200 );

			form.Controls.Add( selector );

		}
		public override bool RegisterClick( SdlDotNet.Input.MouseButtonEventArgs e )
		{
            foreach (Control ctrl in form.Controls)
            {
                if (ctrl.IsPointWithinControl(e.Position))
                {
                    System.Console.WriteLine("GuiLayer: a control was clicked: "+ctrl.GetType().Name);
                    ctrl.Click(e);
                }
            }
			return false;
			//return base.RegisterClick();
		}

		public override Surface RenderSurface()
		{
			//Font font = new Font( @"c:\windows\fonts\arial.ttf", 15 );
			//TextSprite tsp = new TextSprite( "foo?", font, Color.White );
			//surface.Fill( Color.Gray );
			//surface.Blit( tsp, new Point(0,0) );
			//return surface;
			form.Render( null );
			return surface;
		}
	}
}
